<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript" src="/static/js/vue.js"></script>
<script type="text/javascript" src="/static/js/jquery-3.3.1.js"></script>
<div id="app">

        <input type="hidden" v-model="goods.gid"/>
        商品名称：<input type="text" v-model="goods.gname"/>
        单价<input type="text" v-model="goods.price"/>
        数量：<input type="text" v-model="goods.num"/>
<!--        产地：<input type="text" v-model="goods.publish"/>-->
        日期：<input type="date" v-model="goods.pubdate"/>
        <input type="button" value="修改" v-on:click="subfrm"/>

</div>
<script type="text/javascript">
    var v=new Vue({
        el:'#app',
        data:{
          goods:{//var a;
              gid:'',
              gname:'',
              price:'',
              num:'',
              pubdate:''
          }
        },
        methods:{
            subfrm:function(){
                $.ajax({
                    url:'/goods/update',
                    //data:v.goods
                    data:{gid:v.goods.gid,gname:v.goods.gname,num:v.goods.num,price:v.goods.price,pubdate:v.goods.pubdate}, //document.getElementById("name").value;  $("#name").val()
                    type:'get',
                    dataType:'json',
                    success:function(res){
                        if(res.code==200){
                            //再次请求index.html
                            location.href="/url/index";
                        }

                    }
                });
            }
        },
        mounted:function(){
            //先取出上个页面存的id
            var gid=localStorage.getItem("gid");
            if(gid!=null) {
                //再去查询数据--ajax，将查询到的结果赋值给goods赋值
                $.ajax({
                    url: '/goods/one/' + gid,
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        console.log(" 修改的商品信息：", res.data);
                        v.goods = res.data;//gid/gname/....type
                        localStorage.removeItem("gid");
                    }
                });
            }
        }
    });
</script>
</body>
</html>